//
//  DoctorDetailView.m
//  QuickCure1
//
//  Created by Haozhong Chen on 2016/11/5.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "DoctorDetailView.h"
#import "FocusDoctorData.h"
#import "FocusDoctorDetailData.h"
#import "UIImageView+WebCache.h"
#import <UIImageView+WebCache.h>

@interface DoctorDetailView ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIButton *button_tiaojian;
@property (weak, nonatomic) IBOutlet UIButton *button_jianjie;
@property (weak, nonatomic) IBOutlet UIButton *button_shijian;
@property (weak, nonatomic) IBOutlet UIImageView *portrait;
@property (weak, nonatomic) IBOutlet UILabel *label_name;
@property (weak, nonatomic) IBOutlet UILabel *label_title;
@property (weak, nonatomic) IBOutlet UILabel *label_hospital;
@property (weak, nonatomic) IBOutlet UIButton *button_flower;
@property (weak, nonatomic) IBOutlet UIButton *button_jinqi;
@property (weak, nonatomic) IBOutlet UIButton *button_yuyueliang;


@property(nonatomic,weak)UILabel*label_jianjie;
@property(nonatomic,weak)UILabel*label_tiaojian1;
@property(nonatomic,weak)UILabel*label_tiaojian2;



@end
@implementation DoctorDetailView

+(instancetype)creatDoctorDetailView
{
    UINib*nib=[UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
    DoctorDetailView*view=[nib instantiateWithOwner:nil options:nil].lastObject;
    return view;
}


-(void)setupUI
{
    UIView*contentView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH*3, SCREEN_HEIGHT-229)];
    [self.scrollView addSubview:contentView];
    //    contentView.backgroundColor=[UIColor lightGrayColor];
    [self.scrollView setContentSize:CGSizeMake(SCREEN_WIDTH*3, SCREEN_HEIGHT-229)];
    
    self.scrollView.delegate=self;
    
    
    //    NSLog(@"%zd",self.scrollView.contentSize);
    
    //需要优化布局设置
    UIView*view_tiaojian=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-229)];
    UIView*view_jianjie=[[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT-229)];
    UIView*view_shijian=[[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*2, 0, SCREEN_WIDTH, SCREEN_HEIGHT-229)];
    [contentView addSubview:view_tiaojian];
    [contentView addSubview:view_jianjie];
    [contentView addSubview:view_shijian];
    
    
    UILabel*label_tiaojian1=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, self.scrollView.bounds.size.width, 150)];
    UILabel*label_tiaojian2=[[UILabel alloc]initWithFrame:CGRectMake(5, 150, self.scrollView.bounds.size.width, 100)];
    UILabel*label_jianjie=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, self.scrollView.bounds.size.width, 150)];
    
    [view_jianjie addSubview:label_jianjie];
    [view_tiaojian addSubview:label_tiaojian1];
    [view_tiaojian addSubview:label_tiaojian2];
    
    UIImage*shijianImage=[UIImage imageNamed:@"shijian"];
    UIImageView*imageView=[[UIImageView alloc]initWithFrame:view_shijian.bounds];
    imageView.image=shijianImage;
    
    [view_shijian addSubview:imageView];
    
    
    self.label_jianjie=label_jianjie;
    self.label_tiaojian1=label_tiaojian1;
    self.label_tiaojian2=label_tiaojian2;
    
    
    [self.button_shijian setBackgroundImage:[UIImage imageNamed:@"buttonBackground"] forState:UIControlStateSelected];
    [self.button_jianjie setBackgroundImage:[UIImage imageNamed:@"buttonBackground"] forState:UIControlStateSelected];
    [self.button_tiaojian setBackgroundImage:[UIImage imageNamed:@"buttonBackground"] forState:UIControlStateSelected];
    self.button_tiaojian.selected=YES;
}

#pragma mark - 点击跳转

- (IBAction)clickedButton_tiaojian:(UIButton *)sender
{
    self.scrollView.contentOffset=CGPointZero;
    self.button_tiaojian.selected=YES;
    self.button_jianjie.selected=NO;
    self.button_shijian.selected=NO;
//    [self.button_tiaojian setBackgroundColor:[UIColor lightGrayColor]];
    
}
- (IBAction)clickedButton_jianjie:(UIButton *)sender {
    
    self.scrollView.contentOffset=CGPointMake(self.scrollView.bounds.size.width, 0);
    self.button_tiaojian.selected=NO;
    self.button_jianjie.selected=YES;
    self.button_shijian.selected=NO;
//    [self.button_jianjie setBackgroundColor:[UIColor lightGrayColor]];
}
- (IBAction)clickedButton_shijian:(UIButton *)sender {
    
    self.scrollView.contentOffset=CGPointMake(self.scrollView.bounds.size.width*2, 0);
    self.button_tiaojian.selected=NO;
    self.button_jianjie.selected=NO;
    self.button_shijian.selected=YES;
//    [self.button_shijian setBackgroundColor:[UIColor lightGrayColor]];
}

#pragma mark - ScrollView滚动的代理方法
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
   
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat offSet=scrollView.contentOffset.x;
    NSLog(@"%f",offSet);
    int index=abs((int)(offSet/scrollView.bounds.size.width));
    NSLog(@"%d",index);
    switch(index)
    {
        case 0:
            self.button_tiaojian.selected=YES;
            self.button_jianjie.selected=NO;
            self.button_shijian.selected=NO;
            
            break;
        case 1:
            self.button_tiaojian.selected=NO;
            self.button_jianjie.selected=YES;
            self.button_shijian.selected=NO;
            break;
        case 2:
            self.button_tiaojian.selected=NO;
            self.button_jianjie.selected=NO;
            self.button_shijian.selected=YES;
            break;
            
        default:
            break;
    }
}

#pragma mark - 设置界面
-(void)setData:(FocusDoctorData *)data
{
    [self setupUI];
   
    _data=data;
    
    
    [self.portrait sd_setImageWithURL:[NSURL URLWithString:data.doctor_portrait] placeholderImage:[UIImage imageNamed:@"illness_img_person.png"] options:SDWebImageRetryFailed];
    
    self.label_name.text=data.doctor_name;
    self.label_title.text=data.doctor_title_name;
    
    
    
    
    //拼接
    NSString*department=self.detailData.department_name;
    if (department)
    {
        self.label_hospital.text=[self.data.doctor_hospital_name stringByAppendingString:[@"-" stringByAppendingString:department]];
    }
    else
    {
        self.label_hospital.text=data.doctor_hospital_name;
    }
    
    
    [self.button_flower setTitle:[@"鲜花量:" stringByAppendingString:data.flower] forState:UIControlStateNormal];
    
    //    [self.flower setTitleColor:kThemeColor forState:UIControlStateNormal];
    
    
    [self.button_jinqi setTitle:[@"锦旗量:" stringByAppendingString:data.banner] forState:UIControlStateNormal];
    
    
    //    [self.banner setTitleColor:kThemeColor forState:UIControlStateNormal];
    
    [self.button_yuyueliang setTitle:[@"预约量:" stringByAppendingString:data.operation_count] forState:UIControlStateNormal];
    
  
     
     
    
    self.label_jianjie.text=@"这个医生,怎么说呢,你懂得";
    self.label_jianjie.font=[UIFont fontWithName:@"Helvetica" size:14];

     
     
     NSMutableString*strSettings=[[NSMutableString alloc]init];
    NSArray*array=@[@"需要一百万",@"要买进口药",@"要打进口针",@"要看进口护士"];
     for (NSString*temp in array)
     {
     [strSettings appendString:temp];
     [strSettings appendString:@"\n"];
     }
     self.label_tiaojian1.text=strSettings.copy;
    self.label_tiaojian1.font=[UIFont fontWithName:@"Helvetica" size:14];
     self.label_tiaojian1.numberOfLines=0;
    
    
    self.label_tiaojian2.text=@"长得帅,又有钱,还智商低";
    self.label_tiaojian2.font=[UIFont fontWithName:@"Helvetica" size:14];
    self.label_tiaojian2.textColor=kThemeColor;
    
    
}

@end
